package ejb;

import Entities.Vehiculo;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class VehiculoFacade extends FacadeAbstracto<Vehiculo> implements VehiculoFacadeLocal {

    @PersistenceContext(unitName = "SGR-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public VehiculoFacade() {
        super(Vehiculo.class);
    }

    @Override
    public Boolean ExisteMatricula(String m) throws Exception{
        Boolean resu = false;
        Query q = em.createNamedQuery("existeMatricula");
        q.setParameter("mat", m);
        Long r = (Long) q.getSingleResult();
        if (r != 0) {
            resu = true;
        }
        return resu;
    }
}